'''
Author: linxuan
Date: 2022-07-11 13:45:48
Description: file content
FilePath: /stealer/src/opensea_upload.py
'''
import pandas as pd
import datetime
from upload import upload


def geneate_opensea_params(item: dict):
    params = dict()
    params['collection'] = item['collection_name']
    params['name'] = item['name']
    params['author'] = item['author']
    params['date'] = datetime.datetime.now().isoformat()[:10]
    params['amount'] = item['items']
    params['type'] = 'picture' if item['content_address'] != "" else 'vedio'
    params['platform'] = 'opensea'
    params['price'] = item['price']
    params['contract_address'] = item['contract_address']
    params['contract_address_link'] = item['contract_address_src']
    params['token_id'] = item['token_id']
    params['token_id_link'] = item['token_id_src']
    params['token_std'] = item['token_std']
    params['blockchain'] = item['blockchain']
    params['content_url'] = item['content_address']
    params['origin_link'] = item['origin_link']
    # params['discription'] = None
    # 清除None和nan的值
    for key, value in params.items():
        if value is None:
            params[key] = ''
    return params


def main():
    df = pd.read_csv('/resources/opensea_result.csv'[1:])
    df.fillna('', inplace=True)
    for item in df.T.to_dict().values():
        # name,price,content_address,contract_address,token_id,token_std,blockchain,origin_link,token_id_src,contract_address_src,collection_name,author,items
        params = geneate_opensea_params(item)
        ok, resp = upload(params)
        if ok == 200:
            print("success upload")
        else:
            print("error: ", resp)
        # break


if __name__ == '__main__':
    main()
